home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
volume1a
/
readme.txt
< prev
Wrap
Text File
|
1998-01-05
|
17KB
|
412 lines
--------------------------------------------
Microsoft Volume Sample Project Readme File
January l998
-------------------------------------------
(c) Microsoft Corporation, 1997
VOLUME.EXE is a self-extracting compressed file that contains a sample
project demonstrating how to set the volume and microphone levels using
Visual Basic.
After downloading and running the self-extracting file, the following files
are copied to the Volume Level Project directory on your hard drive:
Form1.frm - the main form in the project
Module1.bas - the module containing the function and type declarations.
Project1.vbp - the project file
Project1.vbw - the project workspace file
Readme.txt - you are currently reading this file.
To set these microphone and volume levels from Visual Basic, use the
following Windows API functions:
- GlobalAlloc - allocates the specified number of bytes from the heap.
- GlobalLock - locks a global memory object and returns a pointer to the
first byte of the object[ASCII 146]s memory block. The memory block
associated with a locked memory object cannot be moved or discarded.
- GlobalFree - frees the specified global memory object and invalidates
its handle.
- mixerClose - closes the specified mixer device.
- mixerGetControlDetails - retrieves details about a single control
associated with an audio line.
- mixerGetDevCaps - queries a specified mixer device to determine its
capabilities.
- mixerGetID - retrieves the device identifier for a mixer device
associated with a specified device handle.
- mixerGetLineControls - retrieves one or more controls associated with an
audio line.
- mixerGetLineInfo - retrieves information about a specific line of a
mixer device.
- mixerGetNumDevs - retrieves the number of mixer devices present in the
system.
- mixerMessage - sends a custom mixer driver message directly to a mixer
driver.
- mixerOpen - opens a specified mixer device and ensures that the device
will not be removed until the application closes the handle.
- mixerSetControlDetails - sets properties of a single control associated
with an audio line.
The next section shows how to create a sample project that uses these
functions to set the volume and microphone levels.
Create the Sample Project
-------------------------
1. Start a new Standard EXE project in Visual Basic. Form1 is created by
default.
2. Add two command buttons, two text boxes, and two labels to Form1.
3. Add a Module to the project by completing the following steps:
- From the Project menu, click Add module. The Add Module dialog box
appears.
- From the New tab, choose Module and click OK. A new module is added
to your project.
4. Copy the following code to the Code window of Module1:
Option Explicit
Public Const MMSYSERR_NOERROR = 0
Public Const MAXPNAMELEN = 32
Public Const MIXER_LONG_NAME_CHARS = 64
Public Const MIXER_SHORT_NAME_CHARS = 16
Public Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
Public Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
Public Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
Public Const MIXERLINE_COMPONENTTYPE_SRC_FIRST = &H1000&
Public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = _
(MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
Public Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = _
(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3)
Public Const MIXERLINE_COMPONENTTYPE_SRC_LINE = _
(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2)
Public Const MIXERCONTROL_CT_CLASS_FADER = &H50000000
Public Const MIXERCONTROL_CT_UNITS_UNSIGNED = &H30000
Public Const MIXERCONTROL_CONTROLTYPE_FADER = _
(MIXERCONTROL_CT_CLASS_FADER Or _
MIXERCONTROL_CT_UNITS_UNSIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_VOLUME = _
(MIXERCONTROL_CONTROLTYPE_FADER + 1)
Declare Function mixerClose Lib "winmm.dll" _
(ByVal hmx As Long) As Long
Declare Function mixerGetControlDetails Lib "winmm.dll" _
Alias "mixerGetControlDetailsA" _
(ByVal hmxobj As Long, _
pmxcd As MIXERCONTROLDETAILS, _
ByVal fdwDetails As Long) As Long
Declare Function mixerGetDevCaps Lib "winmm.dll" _
Alias "mixerGetDevCapsA" _
(ByVal uMxId As Long, _
ByVal pmxcaps As MIXERCAPS, _
ByVal cbmxcaps As Long) As Long
Declare Function mixerGetID Lib "winmm.dll" _
(ByVal hmxobj As Long, _
pumxID As Long, _
ByVal fdwId As Long) As Long
Declare Function mixerGetLineControls Lib "winmm.dll" _
Alias "mixerGetLineControlsA" _
(ByVal hmxobj As Long, _
pmxlc As MIXERLINECONTROLS, _
ByVal fdwControls As Long) As Long
Declare Function mixerGetLineInfo Lib "winmm.dll" _
Alias "mixerGetLineInfoA" _
(ByVal hmxobj As Long, _
pmxl As MIXERLINE, _
ByVal fdwInfo As Long) As Long
Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
Declare Function mixerMessage Lib "winmm.dll" _
(ByVal hmx As Long, _
ByVal uMsg As Long, _
ByVal dwParam1 As Long, _
ByVal dwParam2 As Long) As Long
Declare Function mixerOpen Lib "winmm.dll" _
(phmx As Long, _
ByVal uMxId As Long, _
ByVal dwCallback As Long, _
ByVal dwInstance As Long, _
ByVal fdwOpen As Long) As Long
Declare Function mixerSetControlDetails Lib "winmm.dll" _
(ByVal hmxobj As Long, _
pmxcd As MIXERCONTROLDETAILS, _
ByVal fdwDetails As Long) As Long
Declare Sub CopyStructFromPtr Lib "kernel32" _
Alias "RtlMoveMemory" _
(struct As Any, _
ByVal ptr As Long, _
ByVal cb As Long)
Declare Sub CopyPtrFromStruct Lib "kernel32" _
Alias "RtlMoveMemory" _
(ByVal ptr As Long, _
struct As Any, _
ByVal cb As Long)
Declare Function GlobalAlloc Lib "kernel32" _
(ByVal wFlags As Long, _
ByVal dwBytes As Long) As Long
Declare Function GlobalLock Lib "kernel32" _
(ByVal hmem As Long) As Long
Declare Function GlobalFree Lib "kernel32" _
(ByVal hmem As Long) As Long
Type MIXERCAPS
wMid As Integer ' manufacturer id
wPid As Integer ' product id
vDriverVersion As Long ' version of the driver
szPname As String * MAXPNAMELEN ' product name
fdwSupport As Long ' misc. support bits
cDestinations As Long ' count of destinations
End Type
Type MIXERCONTROL
cbStruct As Long ' size in Byte of MIXERCONTROL
dwControlID As Long ' unique control id for mixer device
dwControlType As Long ' MIXERCONTROL_CONTROLTYPE_xxx
fdwControl As Long ' MIXERCONTROL_CONTROLF_xxx
cMultipleItems As Long ' if MIXERCONTROL_CONTROLF_MULTIPLE
' set
szShortName As String * MIXER_SHORT_NAME_CHARS ' shor